﻿using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Controllers;
using Abp.Web.Models;
using Batman.FormGenerator.Services;
using Microsoft.AspNetCore.Mvc;

namespace Batman.FormGenerator.Controllers
{
    public class FormController : AbpController
    {
        public FormAppSvc FormAppSvc { get; set; }

        public ActionResult Index(PagedResultRequestDto page)
        {
            var model = FormAppSvc.GetForms(page);
            return View(model);
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(CreateFormInput model)
        {
            if (!ModelState.IsValid)
            {
                return Json(new AjaxResponse(false));
            }

            var result = FormAppSvc.Create(model);

            return Json(result);
        }

        public JsonResult Get(int id)
        {
            var result = FormAppSvc.Get(id);
            return Json(result);
        }
    }
}
